home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bluep.swf / scripts / __Packages / SoundPlayer.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  4.2 KB  |  149 lines

  1. class SoundPlayer
  2. {
  3.    var channelsAvailable;
  4.    var channel1;
  5.    var channel2;
  6.    var channel3;
  7.    var externalSoundVolume;
  8.    var start;
  9.    function SoundPlayer()
  10.    {
  11.       this.channelsAvailable = new Array(true,true,true);
  12.       this.channel1 = new Sound();
  13.       this.channel2 = new Sound();
  14.       this.channel3 = new Sound();
  15.       this.externalSoundVolume = 100;
  16.    }
  17.    function CleanSounds(intIndex)
  18.    {
  19.       this.channelsAvailable[intIndex] = true;
  20.    }
  21.    function PlaySound(linkIdentifier)
  22.    {
  23.       if(_global.soundOn == true)
  24.       {
  25.          var thisRef = this;
  26.          if(this.channelsAvailable[0] == true)
  27.          {
  28.             this.channelsAvailable[0] = false;
  29.             delete this.channel1;
  30.             this.channel1 = new Sound();
  31.             this.channel1.attachSound(linkIdentifier);
  32.             this.channel1.setVolume(100);
  33.             this.channel1.start(0,0);
  34.             this.channel1.onSoundComplete = function()
  35.             {
  36.                thisRef.CleanSounds(0);
  37.             };
  38.          }
  39.          else if(this.channelsAvailable[1] == true)
  40.          {
  41.             this.channelsAvailable[1] = false;
  42.             delete this.channel2;
  43.             this.channel2 = new Sound();
  44.             this.channel2.attachSound(linkIdentifier);
  45.             this.channel2.setVolume(100);
  46.             this.channel2.start(0,0);
  47.             this.channel2.onSoundComplete = function()
  48.             {
  49.                thisRef.CleanSounds(1);
  50.             };
  51.          }
  52.          else
  53.          {
  54.             this.channelsAvailable[0] = false;
  55.             delete this.channel1;
  56.             this.channel1 = new Sound();
  57.             this.channel1.attachSound(linkIdentifier);
  58.             this.channel1.setVolume(100);
  59.             this.channel1.start(0,0);
  60.             this.channel1.onSoundComplete = function()
  61.             {
  62.                thisRef.CleanSounds(0);
  63.             };
  64.          }
  65.       }
  66.    }
  67.    function PlayBubbleSound(linkIdentifier)
  68.    {
  69.       if(_global.soundOn == true)
  70.       {
  71.          var thisRef = this;
  72.          if(this.channelsAvailable[2] == true)
  73.          {
  74.             this.channelsAvailable[2] = false;
  75.             delete this.channel3;
  76.             this.channel3 = new Sound();
  77.             this.channel3.attachSound(linkIdentifier);
  78.             this.channel3.setVolume(100);
  79.             this.channel3.start(0,0);
  80.             this.channel3.onSoundComplete = function()
  81.             {
  82.                thisRef.CleanSounds(2);
  83.             };
  84.          }
  85.       }
  86.    }
  87.    function PlayExternalSound(urlPath)
  88.    {
  89.       var thisRef = this;
  90.       if(this.channelsAvailable[0] == true)
  91.       {
  92.          this.channelsAvailable[0] = false;
  93.          delete this.channel1;
  94.          this.channel1 = new Sound();
  95.          this.channel1.loadSound(urlPath,false);
  96.          this.channel1.setVolume(this.externalSoundVolume);
  97.          this.channel1.onLoad = function(loadedOK)
  98.          {
  99.             if(loadedOK)
  100.             {
  101.                this.start();
  102.             }
  103.          };
  104.          this.channel1.onSoundComplete = function()
  105.          {
  106.             thisRef.CleanSounds(0);
  107.          };
  108.       }
  109.       else if(this.channelsAvailable[1] == true)
  110.       {
  111.          this.channelsAvailable[1] = false;
  112.          delete this.channel2;
  113.          this.channel2 = new Sound();
  114.          this.channel2.loadSound(urlPath,false);
  115.          this.channel2.setVolume(this.externalSoundVolume);
  116.          this.channel2.onLoad = function(loadedOK)
  117.          {
  118.             if(loadedOK)
  119.             {
  120.                this.start();
  121.             }
  122.          };
  123.          this.channel2.onSoundComplete = function()
  124.          {
  125.             thisRef.CleanSounds(1);
  126.          };
  127.       }
  128.       else
  129.       {
  130.          this.channelsAvailable[0] = false;
  131.          delete this.channel1;
  132.          this.channel1 = new Sound();
  133.          this.channel1.loadSound(urlPath,false);
  134.          this.channel1.setVolume(this.externalSoundVolume);
  135.          this.channel1.onLoad = function(loadedOK)
  136.          {
  137.             if(loadedOK)
  138.             {
  139.                this.start();
  140.             }
  141.          };
  142.          this.channel1.onSoundComplete = function()
  143.          {
  144.             thisRef.CleanSounds(0);
  145.          };
  146.       }
  147.    }
  148. }
  149.